﻿function Editor() {
}
Editor.app = "/qlns";
var url = "http://" + window.location.host.replace("http://", "");
Editor.Url = "http://" + window.location.host.replace("http://", "");
var aurl = Editor.Url.split(':');
console.log("aurl.length : " + aurl.length);
if (aurl.length === 2) {
    Editor.Url = url + Editor.app;
}
else {
    Editor.Url = url;
}

Editor.items = "items";
Editor.login = "login";
function convertDate(str) {
    var as = str.split('-');    
    var dt = new Date();
    if (as.lenght >= 3) {
        var dd = parent(as[2], 10) - 1;
        var mm = parent(as[1], 10);
        var yy = parent(as[0], 10);
        dt = new Date(yy, mm, dd);
    }
    return dt;
}
//luu tru du lieu tai may client. Giam bot tinh nang goi request len server
Editor.Save = function (obj, name) {
    localStorage.setItem(name, JSON.stringify(obj));    
}
// doc lai du lieu vua duoc luu o client
Editor.read = function (name) {
    if (localStorage.getItem(name) != null) {
        var results = JSON.parse(localStorage.getItem(name));        
        return results;
    }
    return new Array();
}

Editor.removeItem = function (name) {
    localStorage.removeItem(name);
}

Editor.getItem = function (item) {
    var arrs = Editor.read(Editor.items);    
    for (var i = 0 ; i < arrs.length; i++) {
        var obj = arrs[i];
        var v1 = String(obj.name).toUpperCase();
        var v2 = String(item).toUpperCase();        
        if (v1 === v2) {
            return obj;
        }
    }
    return null;
}

String.prototype.replaceAll = function (strTarget, strSubString) {
    var strText = this;
    var indexString = strText.indexOf(strTarget);
    while (indexString != -1) {
        strText = strText.replace(strTarget, strSubString);
        indexString = strText.indexOf(strTarget);
    }
    return strText;
}

Array.prototype.contains = function (value) {
    for (var k = 0; k < this.length; k++)
        if (value === this[k])
            return true;
    return false;
}

Array.prototype.searchIndex = function (value) {
    for (var k = 0; k < this.length; k++)
        if (value === this[k])
            return k;
    return -1;
}

Array.prototype.indexOf = function (value) {
    for (var k = 0; k < this.length; k++)
        if (value === this[k])
            return k;
    return -1;
}

Array.prototype.clone = function () {
    var result = new Array();
    for (var k = 0; k < this.length; k++) {
        result.push(this[k]);
    }
    return result;
}